package com.miku.blog.controller;

import com.miku.blog.annotation.SystemLog;
import com.miku.blog.domain.pojo.ResponseResult;
import com.miku.blog.service.UploadFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author shkstart
 * @create ${}YEAR-05-29 17:15
 */

@Api(tags = "后台管理系统[文件上传]")
@RequestMapping("/admin")
@RestController
public class UploadFileController {

    @Autowired
    private UploadFileService uploadFileService;

    @SystemLog(notes = "上传文章封面{后台管理系统}")
    @ApiOperation(value = "上传文章封面接口",notes = "上传文章封面")
    @PostMapping("/articles/images")
    public ResponseResult uploadArticlesImages(@RequestParam("file") MultipartFile file){
        return uploadFileService.uploadArticlesImages(file);
    }


    @SystemLog(notes = "取消已上传的文章封面{后台管理系统}")
    @ApiOperation(value = "取消已上传的文章封面接口",notes = "取消已上传的文章封面 { 删除已上传的对应文件 }")
    @DeleteMapping("/articles/delImages")
    public ResponseResult deleteArticlesImages(@RequestParam("articleCover") String articleCover){
        return uploadFileService.deleteArticlesImages(articleCover);
    }



    @SystemLog(notes = "上传说说图片{后台管理系统}")
    @ApiOperation(value = "上传说说图片接口")
    @PostMapping("/talks/images")
    public ResponseResult uploadTalkImage(@RequestParam("file") MultipartFile multipartFile){
        return uploadFileService.uploadTalkImage(multipartFile);
    }

    @SystemLog(notes = "取消已上传的说说图片{后台管理系统}")
    @ApiOperation(value = "取消已上传的说说图片接口")
    @DeleteMapping("/talks/delImages")
    public ResponseResult delTalkImage(@RequestParam("filePath") String filePath){
        return uploadFileService.delTalkImage(filePath);
    }


    @SystemLog(notes = "上传相册封面/图片{后台管理系统}")
    @ApiOperation(value = "上传相册封面/图片接口")
    @PostMapping("/photos/albums/cover")
    public ResponseResult uploadPhotoAlbumCover(@RequestParam("file") MultipartFile multipartFile){
        return uploadFileService.uploadPhotoAlbumCover(multipartFile);
    }


    @SystemLog(notes = "取消上传相册封面/图片{后台管理系统}")
    @ApiOperation(value = "取消上传相册封面/图片接口")
    @DeleteMapping("/photos/albums/delCover")
    public ResponseResult delPhotoAlbumCover(@RequestParam("filePath") String filePath){
        return uploadFileService.delPhotoAlbumCover(filePath);
    }


    @SystemLog(notes = "上传博客网页封面{后台管理系统}")
    @ApiOperation(value = "上传博客网页封面接口")
    @PostMapping("/page/cover")
    public ResponseResult uploadWebsitePageCover(@RequestParam("file") MultipartFile multipartFile){
        return uploadFileService.uploadWebsitePageCover(multipartFile);
    }

    @SystemLog(notes = "取消上传博客网页封面{后台管理系统}")
    @ApiOperation(value = "取消上传博客网页封面接口")
    @DeleteMapping("/page/delCover")
    public ResponseResult delWebsitePageCover(@RequestParam("filePath") String filePath){
        return uploadFileService.delWebsitePageCover(filePath);
    }


    @SystemLog(notes = "上传博客资源图片{后台管理系统}")
    @ApiOperation(value = "上传博客资源图片接口")
    @PostMapping("/website/config/images")
    public ResponseResult uploadWebsiteConfigImage(@RequestParam("file") MultipartFile multipartFile){
        return uploadFileService.uploadWebsiteConfigImage(multipartFile);
    }


    @SystemLog(notes = "取消上传博客资源图片{后台管理系统}")
    @ApiOperation(value = "取消上传博客资源图片接口")
    @DeleteMapping("/website/config/delImages")
    public ResponseResult delWebsiteConfigImage(@RequestParam("filePath") String filePath){
        return uploadFileService.delWebsiteConfigImage(filePath);
    }

}
